package com.dataaccess.dataaccess.web.service;

import cn.hutool.json.JSONObject;
import com.dataaccess.dataaccess.common.base.BaseService;
import com.dataaccess.dataaccess.support.model.RespEntity;
import com.dataaccess.dataaccess.support.utils.DateUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: YangYu
 * @ClassName: WaterImmersionService
 * @Date: Created in 18:44 2023/11/29
 * @Description: 水浸
 */
@Service
public class WaterImmersionService extends BaseService {

    @Resource
    private AsyncService asyncService;

    /**
     * @Author YangYu
     * @Description 山东123物联网（D10_NB）
     * @Date Created in 10:43 2021/11/24
     * @Param [jsonParam]
     */

    public RespEntity D10_NB(JSONObject jsonParam) throws Exception {
        //设备号
        String number = jsonParam.getStr("IMEI");
        //时间
        String time = DateUtils.contextLoads(jsonParam.getLong("timestamp"));
        //最终推送数据
        JSONObject jsonParamN = new JSONObject();
        jsonParamN.put("number", number);
        //只校验事件
        if (jsonParam.getStr("messageType").equals("eventReport")){
            JSONObject eventContent = jsonParam.getJSONObject("eventContent");
            if (!eventContent.containsKey("soaking_state")){
                return RespEntity.success();
            }
            //报警状态
            String soaking_state = eventContent.getStr("soaking_state");
            if (soaking_state.equals("1")){
                jsonParamN.put("interfaceType", "1");
                jsonParamN.put("content", "水浸告警");
                jsonParamN.put("alarmTypeName", "水浸告警");
                jsonParamN.put("alarmtime", time);
                jsonParamN.put("deviceClassify", 20);
                fireFightingiot(jsonParamN, "communication", "notificationAlarmHandel", "alarmInfo");
                //异步更新设备状态
                jsonParamN.put("state","2");
                asyncService.updateDeviceCurrentState(jsonParamN);
            }
        }
        if (jsonParam.getStr("messageType").equals("dataReport")){
            jsonParamN.put("state","1");
            asyncService.updateDeviceCurrentState(jsonParamN);
        }
        //解析数据结束-------------------------------------------------------------------------------------------------------
        return RespEntity.success();
    }
}
